package com.quarkus.cloud.controller;

import io.quarkus.tika.TikaParser;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;
import java.time.Duration;
import java.time.Instant;

@Path("/parse")
@Slf4j
public class TikaParserController {
    @Inject
    TikaParser parser;

    @POST
    @Path("/text")
    @Consumes({"application/pdf", "application/vnd.oasis.opendocument.text"})
    @Produces(MediaType.TEXT_PLAIN)
    public String extractText(InputStream stream) {
        Instant start = Instant.now();
        String text = parser.getText(stream);
        Instant finish = Instant.now();
        log.info(Duration.between(start, finish).toMillis() + " mls have passed");
        return text;
    }
}
